<!--
*@Author: QWP
*@Description: 预警处置编辑
*@Date: 2024-07-08 17:04:38
-->
<template>
  <a-layout class="f-h-100 s-bg-white">
    <a-layout-header style="padding: 0; background: #fff; height: auto"
      v-if="showTitle">
      <a-row style="font-size: 16px; color: #333"
        align="middle">
        预警企业 
        <span style="margin-left: 20px; font-weight: 900">{{ params['companyName'] }}</span>
        <a-tag :color="leverColor" style="margin-left: 10px; height: max-content">{{ levelText }}级</a-tag>
      </a-row>
    </a-layout-header>
    <u-table-content>
      <u-table
        :columns="columns"
        :data="tabData"
        :loading="loading"
        :scroll="{y: scroll ? scroll : useTableScroll() }"
        :rowSelection="null"
        v-model:pagination="pagenation"
        @change="getInfo">
      </u-table>
    </u-table-content>
  </a-layout>
</template>

<script lang='ts' setup>
import { ref, reactive, computed, onMounted, watch, h, useAttrs } from 'vue' 
import { useRoute, useRouter } from 'vue-router'
import { _IColumnProps } from '@/components/common/tableEdit/interface.ts'
import { nullC, numberC } from '@/util/common'
import { levMainColor } from '@/views/index/emergencyIndex/data'
import { useTableScroll } from "@/hooks/useTable";
import { formatWarnLevel } from '@/views/oa/warning/sumWarning/utils.ts'
import * as sumWarningApi from '@/service/emergency/sumWarning'
const props = withDefaults(
  defineProps<{
    params: object,
    showTitle?: boolean,
    scroll?: object,
    noView?: boolean
  }>(), {
    noView: false,
    showTitle: true
  }
)

const attrs = useAttrs()
const route = useRoute()

const emits = defineEmits(['callBack'])

const leverColor = computed(() => levMainColor[numberC(props.params['riskLevel']) - 1])
const levelText = computed(() => {
  let text = { 1: '一', '2': '二', 3: '三', 4: '四'}
  return nullC(text[props.params['riskLevel']])
})

let pagenation = reactive({
  total: 0,
  current: 1,
  pageSize: 50,
  showTotal: total => `共 ${total} 条`
})
const searchF = reactive({});

// 列表
const loading = ref<boolean>(false)
const tabData = ref<any[]>([]);
let columns: Array<_IColumnProps> = reactive([
  { dataIndex: "index", title: "序号", width: 50, align: 'center',
    customRender: ({ index }) => index += 1
  },
  { dataIndex: "warnType", title: "预警类型", width: 100 },
  { dataIndex: "warnSource", title: "预警来源", width: 100 },
  { dataIndex: "deviceContent", title: "传感器预警内容", width: 200 },
  { dataIndex: "personContent", title: "人员预警内容", width: 100 },
  { dataIndex: "warnLevel", title: "预警等级", width: 150, align: 'center',
    customRender: ({ text }) => {
      const text1 = {
        '一级': '1', '二级': '2', '三级': '3', '四级': '4'
      }
      return text ? formatWarnLevel(text1[text]) : ''
    }
  },
  { dataIndex: "warnDate", title: "预警开始时间 ", width: 150, align: 'center' },
  { dataIndex: "fkInfo", title: "企业反馈情况", width: 150 },
]);

const getInfo = async() => {
  loading.value = true;
  try {
    searchF.current = pagenation.current;
    searchF.size = pagenation.pageSize;
    searchF.mineId = nullC(props.params['mineId'])
    const res = await sumWarningApi.getWarnDetails(searchF)
    if(res.code == 0) {
      emits('callBack', res.data.warnDetailsList || [])
      tabData.value = res.data.warnDetailsList.records || []
      pagenation.total = numberC(res.data.warnDetailsList.total) || 0
    }
  } catch (error) { }
  loading.value = false;
}

// 弹窗关闭
const dialogClose = () => {}

watch(() => attrs.open, (nval, oval) => {
  if(nval == true) {
    getInfo()
  }
}, { immediate: true })

defineExpose({
  pagenation,
  columns,
  getInfo
})
</script>

<style lang='scss' >
</style>